/*

 * Awesome Blogger Page Navigation by Onlinetrick *
 * Rev 248 on May 7, 2010 *
 * Source at http://code.google.com/p/rilwis/source/browse/trunk/blogger *

*/

var n=1, h=[""];
var flag=0;
var e_max=0;
var d_max=2;

function pageNavi(o){
	var m=location.href;
	
	var	l=m.indexOf("/search/label/")!=-1,
		a=l?m.substr(m.indexOf("/search/label/")+14,m.length):"";
		
	a=a.indexOf("?")!=-1?a.substr(0,a.indexOf("?")):a;
	
	var g=l?"/search/label/"+a+"?updated-max=":"/search?updated-max=",
		k=o.feed.entry.length,
		//k=o.feed.openSearch$totalResults.$t,
		e=Math.ceil(k/pageNaviConf.perPage);
	
	//alert("l: " + e + " a: " + a + "m: " + m + "g: " + g + "e: " + e);
	
	if(e<=1){
		return
	}
	
	l?h.push("/search/label/"+a+"?max-results="+pageNaviConf.perPage):h.push("/?max-results="+pageNaviConf.perPage);
	
	for(var d=2;d<=e;d++){
		var c=(d-1)*pageNaviConf.perPage-1,
			b=o.feed.entry[c].published.$t,
			f=b.substring(0,19)+b.substring(23,29);
			
		f=encodeURIComponent(f);
		
		if(m.indexOf(f)!=-1){
			if (a == "") {
				n=d_max;
			} else {
				n=d_max;
			}		
			
		}
		
		h.push(g+f+"&max-results="+pageNaviConf.perPage);
		d_max++;
	}

	//alert("I am an alert box! - " + e + " - " + o.feed.openSearch$totalResults.$t);
	
	if (flag == 1 || a != "") {
		e_max=e_max+e;
		pageNavi.show(h,n,e_max);
	} else {
		e_max=e;
	}
	
	
	flag++;
	
}

pageNavi.show=function(f,e,a){
	//alert("N/E - " + e);
	var d=Math.floor((pageNaviConf.numPages-1)/2),
		g=pageNaviConf.numPages-1-d,
		c=e-d;

		
		
	if(c<=0){
		c=1
	}
	
	endPage=e+g;
		
	if((endPage-c)<pageNaviConf.numPages){
		endPage=c+pageNaviConf.numPages-1
	}
	
	if(endPage>a){
		endPage=a;
		c=a-pageNaviConf.numPages+1
	}
	
	if(c<=0){
		c=1
	}
	
	var b='<span class="pages">Page '+e+' of '+a+"</span> ";
	
	if(c>1){
		b+='<a href="'+f[1]+'">'+pageNaviConf.firstText+"</a>"
	}
	
	if(e>1){
		b+='<a href="'+f[e-1]+'">'+pageNaviConf.prevText+"</a>"
	}
	
	for(i=c;i<=endPage;++i){
		if(i==e){
			b+='<span class="current">'+i+"</span>"
			}else{
			b+='<a href="'+f[i]+'">'+i+"</a>"
		}
	}
	
	if(e<a){
		b+='<a href="'+f[e+1]+'">'+pageNaviConf.nextText+"</a>"
	}
	
	if(endPage<a){
		b+='<a href="'+f[a]+'">'+pageNaviConf.lastText+"</a>"
	}
	
	document.write(b)
};
	
(

	function()
	{
		var b=location.href;
		
		if(b.indexOf("?q=")!=-1||b.indexOf(".html")!=-1)
		{
			return
		}
		
		var d=b.indexOf("/search/label/")+14;
		
		if(d!=13)
		{
			var c=b.indexOf("?"),a=(c==-1)?b.substring(d):b.substring(d,c);
			
			document.write('<script type="text/javascript" src="/feeds/posts/summary/-/'+a+'?alt=json-in-script&callback=pageNavi&max-results=99999"><\/script>')
			document.write('<script type="text/javascript" src="/feeds/posts/summary/-/'+a+'?alt=json-in-script&callback=pageNavi&max-results=99999&start-index=501"><\/script>')
		}
		else
		{
			document.write('<script type="text/javascript" src="/feeds/posts/summary?alt=json-in-script&callback=pageNavi&max-results=99999"><\/script>')
			document.write('<script type="text/javascript" src="/feeds/posts/summary?alt=json-in-script&callback=pageNavi&max-results=99999&start-index=501"><\/script>')
		}
			
	}
			
)();